﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Factory
{
    /// <summary>
    /// 抽象产品类型
    /// </summary>
    public interface IProduct
    {
        string Name { get; }//约定的抽象产品所必须具有的特征
    }
    //具体产品类型
    public class ProductA : IProduct
    {
        public string Name => "A";
    }

    public class ProductB : IProduct
    {
        public string Name => "B";

    }

    public interface IFactory//抽象工厂
    {
        IProduct Create();//每个工厂所需要具有的工厂方法--创建产品
    }

    //抽象工厂的实例
    public class FactoryA : IFactory
    {
        public IProduct Create()
        {
            return new ProductA();
        }
    }

    public class FactoryB : IFactory
    {
        public IProduct Create()
        {
            return new ProductB();
        }
    }





    public class Client
    {
        public void SomeMethod()
        {
            IFactory factory = new FactoryA();//获取了抽象的Factory的同时与FactoryA产生了依赖。

            IProduct product = factory.Create();//后续操作仅依赖抽象的IFactory和Iprodcut。
        }
    }

   
}
